/**
 * LandmarkService.java 
 * Copyright © 2015-3015, 杭州泊享网络科技有限公司
 * 
 * @author Liu Tao
 * @create 2014年11月19日
 */
package com.pshare.artemis.basic.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pshare.artemis.basic.bean.Landmark;
import com.pshare.artemis.basic.mapper.LandmarkMapper;
import com.pshare.tool.StaticMapStore;

/**
 * 地区地标业务层
 */
@Service
@Transactional
public class LandmarkService {

    @Autowired
    private LandmarkMapper landmarkMapper;

    public List<Landmark> getLandmarks(Integer districtId) {

    	Map<Integer, List<Landmark>> rsMap = (Map<Integer, List<Landmark>>) StaticMapStore.getInstance().get(StaticMapStore.Key.LANDMARKMAP);
    	List<Landmark> landmarks = rsMap.get(districtId);
    	if (landmarks == null) {
        	landmarks = landmarkMapper.queryByDistrictId(districtId);
        	rsMap.put(districtId, landmarks);
        }
        
        return landmarks;
    }
	
    /**
     * 增加地标
     * @param districtId
     * @param name
     */
	public void addLandMark(Integer districtId, String name) {
		int count = landmarkMapper.getCount(districtId, name);
		if (count > 0) {
			return;
		} else {
			landmarkMapper.add(districtId, name);
			Map<Integer, List<Landmark>> rsMap = (Map<Integer, List<Landmark>>) StaticMapStore.getInstance().get(StaticMapStore.Key.LANDMARKMAP);
			rsMap.remove(districtId);
		}
	}
	
}
